package cn.oracle.eshop.auth.visitor;

import cn.oracle.eshop.auth.composite.PriorityNode;
import cn.oracle.eshop.auth.dao.AccountPriorityRelationshipDAO;
import cn.oracle.eshop.auth.dao.PriorityDAO;
import cn.oracle.eshop.auth.dao.RolePriorityRelationshipDAO;
import cn.oracle.eshop.auth.domain.PriorityDo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/** 权限树节点的删除访问者
 * @author wyh
 * @ClassName PriorityNodeRemoveVisitor
 * @date 2022/1/22 /18:40
 */

public class PriorityNodeRemoveVisitor implements  PriorityNodeVisitor{
    /**权限管理模块的DAO组件*/
    private PriorityDAO priorityDAO;

    public PriorityNodeRemoveVisitor(PriorityDAO priorityDAO) {
        this.priorityDAO = priorityDAO;
    }
/**访问权限树节点
 * @param node 权限节点
 * */
    @Override
    public void visit(PriorityNode node) {
        List<PriorityDo> priorityDos=priorityDAO.listChildPriorities(node.getId());
        if(priorityDos !=null && priorityDos.size()>0){
            for (PriorityDo priorityDo : priorityDos) {
                //把do的数据克隆到Node里面,拿到所有的子节点
                PriorityNode priorityNode=priorityDo.clone(PriorityNode.class);
                priorityNode.accept(this);
            }
        }
        removePriority(node);
    }
    /**删除权限*/
    private void removePriority(PriorityNode node){
        priorityDAO.removePriority(node.getId());
    }

}
